2020-2021 Sunseeker Telemetry and Lighting System
sd24_ex2_singleConversionGroupChannels.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430i20xx SD24 Example 02 - SD24, Single Conversion on a Group of 3 Channels
34 //
35 // Description: This program uses the SD24 module to perform a single
36 // conversion on a group of channels (0, 1 and 2). A SD24 interrupt occurs
37 // when the conversions have completed.
38 //
39 // Test by applying voltages to the 3 input channels and setting a breakpoint
40 // at the indicated line. Run program until it reaches the breakpoint, then use
41 // the debugger's watch window to view the conversion results.
42 //
43 // Results (upper 16 bits only) are stored in the array "results"
44 //
45 // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
46 // * Ensure low_level_init.c is included when building/running this example *
47 //
48 // Notes: For minimum Vcc required for SD24 module - see datasheet
49 // 100nF cap btw Vref and AVss is recommended when using 1.2V ref
50 //
51 // MSP430i20xx
52 // -----------------
53 // /|\| |
54 // | | |
55 // --|RST |
56 // | |
57 // Vin1+ -->|A0.0+ VREF |---+
58 // Vin1- -->|A0.0- | |
59 // Vin2+ -->|A1.0+ | -+- 100nF
60 // Vin2- -->|A1.0- | -+-
61 // Vin3+ -->|A2.0+ | |
62 // Vin3- -->|A2.0- AVss |---+
63 //
64 // T. Witt
65 // Yang Lu
66 // Texas Instruments, Inc
67 // June 2014
68 // Built with Code Composer Studio v5.5
69 //******************************************************************************
70 #include "driverlib.h"
71 
72 /* Array to store SD24 conversion results */
73 uint16_t results[3];
74 
75 void main(void) {
76  // Stop WDT
77  WDT_hold(WDT_BASE);
78 
79  // Internal ref
80  SD24_init(SD24_BASE, SD24_REF_INTERNAL);
81 
82  //Group with Channel 0
83  SD24_initConverterAdvancedParam param = {0};
84  param.converter = SD24_CONVERTER_0;
85  param.conversionMode = SD24_SINGLE_MODE;
86  param.groupEnable = SD24_GROUPED;
87  param.inputChannel = SD24_INPUT_CH_ANALOG;
88  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
89  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
90  param.oversampleRatio = SD24_OVERSAMPLE_256;
91  param.gain = SD24_GAIN_1;
92  SD24_initConverterAdvanced(SD24_BASE, &param);
93 
94  //Group with Channel 1
95  param.converter = SD24_CONVERTER_1;
96  param.conversionMode = SD24_SINGLE_MODE;
97  param.groupEnable = SD24_GROUPED;
98  param.inputChannel = SD24_INPUT_CH_ANALOG;
99  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
100  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
101  param.oversampleRatio = SD24_OVERSAMPLE_256;
102  param.gain = SD24_GAIN_1;
103  SD24_initConverterAdvanced(SD24_BASE, &param);
104 
105  // Enable interrupt
106  param.converter = SD24_CONVERTER_2;
107  param.conversionMode = SD24_SINGLE_MODE;
108  param.groupEnable = SD24_NOT_GROUPED;
109  param.inputChannel = SD24_INPUT_CH_ANALOG;
110  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
111  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
112  param.oversampleRatio = SD24_OVERSAMPLE_256;
113  param.gain = SD24_GAIN_1;
114  SD24_initConverterAdvanced(SD24_BASE, &param);
115  SD24_enableInterrupt(SD24_BASE, SD24_CONVERTER_2, SD24_CONVERTER_INTERRUPT);
116 
117  // Delay ~200us for 1.2V ref to settle
118  __delay_cycles(3200);
119 
120  while(1) {
121  __no_operation(); // SET BREAKPOINT HERE
122  // Start conversion
123  SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_2);
124  // Enter LPM0 w/ interrupts
125  __bis_SR_register(LPM0_bits | GIE);
126  // For debugger
127  __no_operation();
128  }
129 }
130 
131 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
132 #pragma vector=SD24_VECTOR
133 __interrupt void SD24_ISR(void) {
134 #elif defined(__GNUC__)
135 void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void) {
136 #else
137 #error Compiler not supported!
138 #endif
139  switch (__even_in_range(SD24IV,SD24IV_SD24MEM3)) {
140  case SD24IV_NONE: break;
141  case SD24IV_SD24OVIFG: break;
142  case SD24IV_SD24MEM0: break;
143  case SD24IV_SD24MEM1: break;
144  case SD24IV_SD24MEM2:
145  results[0] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0); // Save CH0 results (clears IFG)
146  results[1] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_1); // Save CH1 results (clears IFG)
147  results[2] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_2); // Save CH2 results (clears IFG)
148  __bic_SR_register_on_exit(LPM0_bits); // Wake up
149  break;
150  case SD24IV_SD24MEM3: break;
151  default: break;
152  }
153 }
MPU_initThreeSegmentsParam param
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
__delay_cycles(500000)